<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>04.对象的扩展.html</title>
</head>
<body>
    <script>
        /**
         * es6 对象简写方式 
         *    如果key和value的变量名 是一样的  只保留一个就可以了
         */
        let name = "小明"
        let age = 20;
        const stu = {
            name,
            age,
            say() {
                console.log(this.name+"在说话....");
            }
        }
        console.log(stu);
        stu.say()
        console.log("=============================");
        const stu02 = {
             age:18,
             get myAge() {
                console.log("取值");
                return  this.age;
             },
             set myAge(a) {
                // console.log("赋值",a);
                if(a < 0  || a>120) {
                    this.age = 18
                }else {
                    this.age = a
                }
             }
         }

         // stu02.age =200
         stu02.myAge = 200;
        //  const result = stu02.myAge 
        //  console.log(result);

         console.log(stu02);
    </script>
    
</body>
</html>